#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "uthash.h"

#include <iso646.h>

void rank(int nums[], int ranks[]);

char* longestDiverseString(int a, int b, int c);

int main()
{
	return 0;
}

char* longestDiverseString(int a, int b, int c)
{
	int aux[] = { a, b, c }, ranks[3] = { 0, 1, 2 }, size = 0, time = 0;
	rank(aux, ranks);
	char* res = (char*)calloc(a + b + c + 1, sizeof(char));
	while (size < a + b + c) {
		printf("[%d,%d,%d]\n",aux[0],aux[1],aux[2]);
		if (time != 2) {
			res[size] = 'a' + ranks[0];
			aux[ranks[0]]--;
			rank(aux, ranks);
			if (res[size++] == ranks[0] + 'a') time++;
		} else {
			int next = -1;
			for (int i = 1; i < 3; ++i)
				if (aux[ranks[i]] > 0) {
					next = ranks[i];
					break;
				}

			if (next == -1) return NULL;
			res[size++] = 'a' + next;
			time = 0;
			aux[next]--;
			rank(aux, ranks);
		}
	}
	return res;
}

void rank(int nums[], int ranks[])
{
	for (int round = 0; round < 2; ++round)
		for (int i = 0; i < 2 - round; i++) {
			if (nums[ranks[i]] < nums[ranks[i + 1]]) {
				int temp = ranks[i];
				ranks[i] = ranks[i + 1];
				ranks[i + 1] = temp;
			}
		}
}
